import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JRootPane;

class MyJFrame extends JFrame implements ActionListener
{
  private static final long serialVersionUID = 1L;
  private int h = 500;
  private int w = 800;
  private int x = 0;
  private int y = 0;
  private Control control;
  private MyJPanel controlpanel;
  private MyJLayeredPane mp;

  public MyJFrame(Control control)
  {
	System.out.println("MyJFrame, MyJFrame(Control control)");
    this.control = control;
    this.setName("MyJFrame");
    this.setTitle("Webservert");
    this.setResizable(false);
    this.setBounds(x, y, w, h);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);
    
    

     mp = (MyJLayeredPane) getLayeredPane();
    
    
    mp.setControl(control);
    controlpanel = new MyJPanel(mp, this);
    this.add(controlpanel, BorderLayout.NORTH);
    MyGlassPane mg = (MyGlassPane) getGlassPane();
    mg.setControl(control);
    this.getGlassPane().setVisible(true);
  }

  public Control getControl()
  {
	System.out.println("MyJFrame, getControl()");
    return control;
  }

  @Override
  protected JRootPane createRootPane()
  {
	System.out.println("MyJFrame, createRootPane()");
    return new MyJRootPane();
  }
  
  @Override
  public void actionPerformed(ActionEvent arg0)
  {
	  System.out.println("MyJLayeredPane, actionPerformed(ActionEvent arg0)");
    if (arg0.getActionCommand() == "start")
    {
    	mp.removeLayers();
      getControl().doStart();
      controlpanel.changeStatusBtn();
    }
    else if (arg0.getActionCommand() == "stop")
    {
    	
      getControl().doStop();
      controlpanel.changeStatusBtn();
    }
  }
   
  public void finalize() throws Throwable
  {
	System.out.println("MyJFrame, finalize()");
  }
  
  public String toString()
  {
	System.out.println("MyJFrame, toString()");
	return super.toString();
  }
}